package com.fantastic.service.zjs.impl;

import com.fantastic.common.exception.LoginException;
import com.fantastic.common.exception.RegisterException;
import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.exception.sql.SelectException;
import com.fantastic.common.utils.IsEmptyUtils;
import com.fantastic.mapper.zjs.AccountMapper;
import com.fantastic.mapper.zjs.UserMapper;
import com.fantastic.model.pojo.zjs.Account;
import com.fantastic.model.pojo.zjs.User;
import com.fantastic.service.zjs.AccountService;
import com.fantastic.service.zjs.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author: rxx
 * @since: 2024/5/28 08:41
 * @description: 用户账号表的service层接口实现类
 */
@Service

public class AccountServiceImpl implements AccountService {

    /**
     * 自动注入账号信息dao层
     */
    @Resource
    private AccountMapper accountMapper;

    /**
     * 自动注入用户信息service层
     */
    @Resource
    private UserMapper userMapper;

    /**
     * 查询
     * 无条件时是查询全部的分页查询
     * 有条件时是查询条件的分页查询
     *
     * @param account
     * @return
     */
    @Override
    public List<Account> listAccount(Account account) {
        List<Account> accounts = accountMapper.listAccount(account);
        if (accounts.size() != 0) {
            return accounts;
        }
        //抛出未查询到数据
        throw new SelectException(RespStatusInfo.SELECT_NULL);
    }

    /**
     * 查询单个账号的信息
     *
     * @param accountId
     * @return
     */
    @Override
    public Account getAccount(Integer accountId) {
        if (accountId != null) {
            Account account = accountMapper.getAccount(accountId);
            if (account != null) {
                return account;
            }
            //抛出查询为null
            throw new SelectException(RespStatusInfo.SELECT_NULL);
        }
        //抛出查询异常
        throw new SelectException(RespStatusInfo.SELECT_ERROR);
    }

    /**
     * 修改账号信息
     * 即可修改密码也可修改手机号，也可以修改账号储蓄，或是其他
     *
     * @param account
     */
    @Override
    public Integer updateAccount(Account account) {
        //判读账号id是否为空
        IsEmptyUtils.integerIsEmpty(new SelectException(RespStatusInfo.DATA_ERROR), account.getAccountId());
        return accountMapper.updateAccount(account);
    }

    /**
     * 删除账号信息
     *
     * @param accountId
     */
    @Override
    public Integer deleteAccount(Integer accountId) {
        return accountMapper.deleteAccount(accountId);
    }
}
